package com.yuan.condition;

import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @Author: Jinsheng·yuan
 * @CreateDate: 2020/1/14 22:15
 * @Description: 实现ImportSelector接口来自定义逻辑返回要导入的组件
 */
public class MyImportSelector implements ImportSelector {
    /**
     *
     * @param importingClassMetadata 当前标注@Import注解的类的所有注解信息
     * @return 返回值就是导入容器中的组件的全类名
     */
    @Override
    public String[] selectImports(AnnotationMetadata importingClassMetadata) {
        //可获取标注@Import注解类的所有注解信息
        System.out.println("importingClassMetadata.getClassName():"+importingClassMetadata.getClassName());
        System.out.println("importingClassMetadata.getAnnotations():"+importingClassMetadata.getAnnotations());

        //return new String[0]; //这里不能返回null,可以返回一个空数组
        return new String[]{"com.yuan.bean.Blue","com.yuan.bean.Yellow"};//导入容器中的组件的全类名
    }
}
